<?php
namespace app\admin\model;


use think\Model;

class Collect extends Model
{
    static public function isHas($article_id , $user_id)
    {
        if(self::where(['article_id' => $article_id, 'user_id' => $user_id])->findOrEmpty()->isEmpty()) return 0;
        else return 1;
    }
    public function user()
    {
        return $this->belongsTo(User::class , 'user_id' , 'id');
    }
    static public function list($user_id)
    {
        $art_id = [];
        $list = self::where('user_id' , $user_id)->column('article_id');
        foreach($list as $key => $v)
        {
            $art_id[] = $v;
        }
        $artList = Article::where(['id' => $art_id])->select();
        return (new Article())->list(['list' => $artList]);
    }
}